import json
import requests
from wxpy import *

bot = Bot(cache_path=True)
boy_friend = bot.search("黄嗣喆")[0]


def auto_reply(text):
    url = 'http://www.tuling123.com/openapi/api'
    api_key = 'c85f0dfaeae34e239a1ccceb86fc4f5a'
    payload = {
        'key':api_key,
        'info':text,
    }
    r = requests.post(url, data=json.dumps(payload))
    result = json.loads(r.content)
    return '[豆渣：]'+result['text']


@bot.register()
def forward_message(msg):
    if msg.sender == boy_friend:
        return auto_reply(msg.text)

embed()